$(document).ready(function() {
	function showTime() {
		//取得現在時間
		var today = new Date();
		//將日期轉為星期，以七天為一個循環
		var weekday = new Array(7);
		weekday[0] = "星期一";
		weekday[1] = "星期二";
		weekday[2] = "星期三";
		weekday[3] = "星期四";
		weekday[4] = "星期五";
		weekday[5] = "星期六";
		weekday[6] = "星期日";
		var y = today.getFullYear() + "年";
		var month = (today.getMonth() + 1) + "月";
		var td = today.getDate() + "日";
		var d = weekday[today.getDay()];
		var apm = (today.getHours() >= 12) ? "下午 " : "上午 ";
		var h = ((today.getHours() > 12) ? today.getHours() - 12 : today.getHours()) + ":";
		var m = ((today.getMinutes() < 10) ? " 0" : " ") + today.getMinutes() + ":";
		var s = ((today.getSeconds() < 10) ? " 0" : " ") + today.getSeconds();
		//計時器讀取變數
		timer($("#Y"), y);
		timer($("#MH"), month);
		timer($("#TD"), td);
		timer($("#D"), d);
		timer($("#APM"), apm);
		timer($("#H"), h);
		timer($("#M"), m);
		timer($("#S"), s);
	}
	//每1000毫秒做一次showTime
	setInterval(showTime, 1000);
	//將物件寫入頁面
	function timer(obj, txt) {
		obj.text(txt);
	}
});